import { defineStore } from 'pinia'
import api from '@/http/index'
import _ from 'lodash'

const useEnterpriseStore = defineStore('enterprise', {
  state: () => ({
    enterprise: {},
    enterpriseId: '',
  }),
  actions: {
    async getEnterpriseInfo(enterpriseId) {
      enterpriseId = enterpriseId || this.enterpriseId
      if (!enterpriseId) return
      if (enterpriseId === this.enterpriseId && _.isEmpty(this.enterprise)) return
      const result = await api.enterprise.getInfo(enterpriseId).catch(() => {})
      this.enterprise = result?.data || {}
      this.enterpriseId = this.enterprise.enterpriseId
      return this.enterprise
    },
  },
})

export default useEnterpriseStore
